
var PicUrl = "http://121.201.110.127:1000/";//图片url
 

//处理图片
function photoFn(img) {
    var iheight = img.height();//img的高度
    //var iwidth = img.width();
    var itemHeight = img.parent().height();//item的高度

    img.css({"margin-top": (itemHeight / 2 -iheight / 2) + "px"});

    //if (iwidth >= iheight) {
    //    img.css({ "margin-top": (itemHeight / 2 - iheight / 2) + "px" });
    //} else {
    //    img.css({ "width": "auto", "height": "100%", "margin": "auto" });
    //}
}

//input输入内容出现删除按钮
function searchFn(conChange,wrap,quxiao){
  if(conChange == ""){
    quxiao.hide();
    wrap.css("border-radius","4px");

  }else{
    quxiao.show();
    wrap.css("border-radius","4px 0 0 4px");
  }
}

//隐藏tabs选项卡
function tabs_show_hide(scope,state,ionicTabsDelegate){
  scope.hideTab = function(){
    ionicTabsDelegate.showBar(false);
  }
  scope.$on('$ionicView.beforeEnter', function () {
    ionicTabsDelegate.showBar(true);
  });
}

//tabs切换
function changeFn(obj, div) {
    obj.each(function (i) {
        obj.eq(i).on("click", function () {
            obj.removeClass("active");
            $(this).addClass("active");
            div.hide().eq(i).show();
        })
    })
}

//倒计时60秒
function codeFn(){
  var getcode = $(".phone .button");
  var s = 60;
  getcode.on("click",function  () {
    timeFn($(this));
  })
  function timeFn (obj) {
    if (s == 0) {
      obj.removeAttr("disabled");
      obj.html("重新发送");
      s = 10;
    }else{
      obj.attr("disabled","true");
      obj.html(s + "秒");
      s --;
      setTimeout(function  () {
        timeFn(obj);
      },1000)
    }
  }
}

//时间格式
Date.prototype.Format = function (fmt) {
    var Week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    "S": this.getMilliseconds() //毫秒
  };
  if (fmt == "W")
  {
      return fmt.replace(/w|W/g, Week[this.getDay()]);
  }
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}

//tobase64string
function Base64_Encode(str) {
  var c1, c2, c3;
  var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var i = 0, len = str.length, string = '';

  while (i < len) {
    c1 = str.charCodeAt(i++) & 0xff;
    if (i === len) {
      string += base64EncodeChars.charAt(c1 >> 2);
      string += base64EncodeChars.charAt((c1 & 0x3) << 4);
      string += "==";
      break;
    }
    c2 = str.charCodeAt(i++);
    if (i === len) {
      string += base64EncodeChars.charAt(c1 >> 2);
      string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
      string += base64EncodeChars.charAt((c2 & 0xF) << 2);
      string += "=";
      break;
    }
    c3 = str.charCodeAt(i++);
    string += base64EncodeChars.charAt(c1 >> 2);
    string += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
    string += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
    string += base64EncodeChars.charAt(c3 & 0x3F);
  }
  return string;
}

//医院功能列表
function getHospitalItems(obj) {
    var item = [];
    if (obj.register == 1) {
        item.push({
            "name": '挂号',
            "class": "guahao"
        });
    }
    if (obj.payment == 1) {
        item.push({
            "name": '缴费',
            "class": "jiaofei"
        });
    }
    if (obj.secure == 1) {
        item.push({
            "name": '保险',
            "class": "baoxian"
        });
    }
    if (obj.examine == 1) {
        item.push({
            "name": '体检',
            "class": "tijian"
        });
    }
    if (obj.takeMedicine == 1) {
        item.push({
            "name": '送药',
            "class": "songyao"
        });
    }
    return item;
}

//获取转化时间倒计时使用
function getLocalTime(S) {
    return new Date(parseInt(S)*1000).Format("mm:ss");
}

 //双击返回
function BackOutApp(fn)
{
	appplus(function(){
		// Android处理返回键 
		var backButtonPress = 0;
		plus.key.addEventListener('backbutton',function(){
			if(this.location.hash.toLowerCase()!='#/home')
			{
				console.log(plus.runtime.appid+'-'+this.location.hash);
//				window.history.back();
				fn();
				return true;
			}
			backButtonPress++;
			if (backButtonPress > 1) {
				plus.runtime.quit();
			} else {
				plus.nativeUI.toast('再按一次退出应用');
			}
			setTimeout(function() {
				backButtonPress = 0;
			}, 1500);
			return false;
		},false);
	});
}
